<template>
  <div>
    <h1>当前求和为: {{ sum }}</h1>
    <!-- 也可以通过v-model:number强制转换 -->
    <select v-model="n">
      <!-- 添加v-bind作为表达式使用 -->
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="allAdd">总数为奇数时再加</button>
    <button @click="waitAdd">延迟添加</button>
  </div>
</template>

<script>
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Count",
  data() {
    return {
      n: 1,
      sum: 0,
    };
  },
  methods: {
    increment() {
      this.sum += this.n;
    },
    decrement() {
      this.sum -= this.n;
    },
    allAdd() {
      //为奇数时再加
      if (this.sum % 2) {
        this.sum += this.n;
      }
    },
    waitAdd() {
      setTimeout(() => {
        this.sum += this.n;
      }, 1000);
    },
  },
};
</script>

<style>
bottom {
  margin-left: 5px;
}
</style>
